package com.huaxin.common.message.util;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.huaxin.common.R;

public class UploadDialog extends Dialog {

    View child;
    ProgressBar pb;
    String msg;
    TextView tip;
    View next;

    @SuppressLint("InflateParams")
    public UploadDialog(Context context, String msg) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        child = getLayoutInflater().inflate(R.layout.upload_dialog, null);
        pb = (ProgressBar) child.findViewById(R.id.progressBar1);
        this.msg = msg;
        tip = (TextView) child.findViewById(R.id.tip);
        next = child.findViewById(R.id.next);
        // setTitle(R.string.tip_title);
        tip.setText(msg);
        setContentView(child);
        next.setVisibility(View.GONE);
    }

    public void setProgress(int p) {
        pb.setProgress(p);
        tip.setText(msg + "  " + p + "%");
        if (p >= pb.getMax()) {
            next();
        }
    }

    public void next() {
        tip.setText(msg);
        pb.setVisibility(View.GONE);
        next.setVisibility(View.VISIBLE);
    }

}
